// 权限指令
import PermissionUtil from '@/utils/permission'

export default {
  // v-permission 指令
  permission: {
    mounted(el, binding) {
      const { value } = binding
      if (value && !PermissionUtil.hasPermission(value)) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  },
  
  // v-role 指令
  role: {
    mounted(el, binding) {
      const { value } = binding
      if (value && !PermissionUtil.hasRole(value)) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  },
  
  // v-any-permission 指令
  anyPermission: {
    mounted(el, binding) {
      const { value } = binding
      if (value && !PermissionUtil.hasAnyPermission(value)) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  },
  
  // v-all-permissions 指令
  allPermissions: {
    mounted(el, binding) {
      const { value } = binding
      if (value && !PermissionUtil.hasAllPermissions(value)) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  },
  
  // v-any-role 指令
  anyRole: {
    mounted(el, binding) {
      const { value } = binding
      if (value && !PermissionUtil.hasAnyRole(value)) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  }
}